/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fandi.model;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Fandy
 */
public class CategoryTableModel extends AbstractTableModel {
    
    private List<CategoryModel> list;

    public CategoryTableModel() {
        list = new ArrayList<>();
    }
    
    public void setList(List<CategoryModel> list) {
        this.list = list;
        fireTableDataChanged(); // Untuk updating table jika ada perubahan pada record
    }
    
    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex) {
            case    0 :
                return list.get(rowIndex).getCode();
            case    1 :
                return list.get(rowIndex).getName();
            case    2 :
                return list.get(rowIndex).getDescription();
            default   :
                return null;
        }
    }
    
    @Override
    public String getColumnName(int columnIndex) {
        switch(columnIndex) {
            case    0 :
                return "Code";
            case    1 :
                return "Category";
            case    2 :
                return "Description";
            default   :
                return null;
        }
    }
    
}
